package top.v5it.japi.plus.example.jdbc.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import top.v5it.japi.plus.core.spring.web.JapiEada;
import top.v5it.japi.plus.example.jdbc.service.AccountService;
import top.v5it.japi.plus.log.JapiOperLog;
import top.v5it.japi.plus.support.limit.JapiLimit;

import java.time.LocalDate;
import java.util.Map;

/**
 * 示例接口
 *
 * @author zhanpu
 * @date 2022/6/20
 */
@Slf4j
//@RestController
//@RequiredArgsConstructor
//@RequestMapping("/v1/example")
public class ExampleController {

    private AccountService accountService;

    @JapiLimit(limit = "1", time = "15")
    @JapiEada(isEncrypt = false)
    @GetMapping("{id}/{resource}")
    public void testDecrypt(@PathVariable("id") Integer id, @PathVariable("resource") String resource) {

        log.info("id[{}]", id);
        log.info("resource[{}]", resource);
    }

    @JapiOperLog("测试")
    @JapiEada(isDecrypt = false)
    @GetMapping("{id}")
    public TestExampleDTO testEncrypt(@PathVariable("id") Integer id) {

        log.info("id[{}]", id);

        TestExampleDTO.Resource resource = new TestExampleDTO.Resource()
                .setTel("18589023487")
                .setIdNum("430682176523908729");

        return new TestExampleDTO()
                .setBirthday(LocalDate.parse("1999-12-20"))
                .setId(1L)
                .setName("zhangshan")
                .setSex("男")
                .setResource(resource);
    }

    @JapiEada(isEncrypt = false)
    @PostMapping("post")
    public void testPostParams(@RequestParam Map<String, String[]> map) {

        log.info("map[{}]", map);
    }

    @GetMapping("get")
    public void testGetParams(@RequestParam Map<String, String[]> map) {

        log.info("map[{}]", map);

    }
}
